<?php 
ob_start();
//header("Content-Type: text/plain");
$wyn = file_get_contents('wyn');
$ind = strpos($wyn,']]')+2;
$plany_tmp = explode('[',trim(substr($wyn,0,$ind)));
$deficyty_tmp = explode('[',trim(substr($wyn,$ind)));
$plany = array(); $deficyty = array();

foreach($plany_tmp as $plan) {
	$plan = trim($plan);
	if(empty($plan)) continue;
	$plany[] = $plan;
}
foreach($deficyty_tmp as $deficyt) {
	$deficyt = trim($deficyt);
	if(empty($deficyt)) continue;
	$deficyty[] = $deficyt;
}

$size = min(count($deficyty),count($plany));

$data = array();

function porowanie($a,$b){
	if( @$a['val'] > $b['val'] ) return 1;
	elseif( @$a['val'] < $b['val'] ) return -1;
	return 0;
}

for($i=0;$i<$size;$i++){
	$deficyt_str = substr($deficyty[$i],0,strpos($deficyty[$i],']'));
	$deficyt = explode(', ', $deficyt_str);
	$deficytabs = array_map('abs',array_map('trim',$deficyt));
	
	$data[] = array(
		'plan' => '[' . substr($plany[$i],0,strpos($plany[$i],']')) . ']',
		'deficyt' => '[' . $deficyt_str . ']',
		'val' => array_sum($deficytabs)/count($deficytabs)
	);
}


	
function proj_plan($el){ return $el['plan']; }
function proj_deficyt($el){ return $el['deficyt']; }

$def = array_map('proj_deficyt',$data);
$pla = array_map('proj_plan',$data); 

$def_str = '['.implode(', ',$def).']';
$pla_str = '['.implode(', ',$pla).']';

ob_end_clean();

echo $pla_str,$def_str;
